<template>
  <div>
    <!-- 子组件通知父组件关闭对话框 -->
    <van-picker
      title="性别"
      show-toolbar
      :columns="columns"
      @confirm=" onConfirm"
      @cancel="onCancel"
      :default-index="localGender"
    />
  </div>
</template>

<script>
import { updateUserName } from '@/api/user'
export default {
  name: 'upDateGander',
  props: {
    value: Number
  },
  data () {
    return {
      localGender: this.value,
      columns: ['男', '女']
    }
  },
  methods: {
    //   确定操作
    async  onConfirm (value, index) {
      try {
        // 发请求
        await updateUserName({ gender: index })
        //   提示成功
        this.$toast.success('操作成功')
        //   更新父组件数据
        this.$emit('input', index)
        // 关闭弹层
        this.$emit('close')
      } catch (e) {
        console.log(e)
        this.$toast(e.message)
      }
    },
    // onChange (picker, value, index) {

    // },
    // 操作取消，关闭对话框
    onCancel () {
      this.$emit('close')
    }
  }

}
</script>

<style lang="less" scoped>
.box {
  padding: 20px;
}
</style>